//
// doPush.cpp for  in /home/jousse_f//workspace/C++/abstractVM
// 
// Made by florian jousseau
// Login   <jousse_f@epitech.net>
// 
// Started on  Mon Feb 13 17:01:40 2012 florian jousseau
// Last update Thu Feb 16 18:57:49 2012 florian jousseau
//

#include "Abstract.hh"
#include "Int8.hh"
#include "Int16.hh"
#include "Int32.hh"
#include "Double.hh"
#include "Float.hh"
#include "convert.hpp"
#include "checkStack.hh"

const VM::t_fct	VM::tab_fct[] =
  {
    {&VM::createInt8, INT8},
    {&VM::createInt16, INT16},
    {&VM::createInt32, INT32},
    {&VM::createFloat, FLOAT},
    {&VM::createDouble, DOUBLE},
    {NULL, NOTHING},
  };

IOperand *VM::createOperand(eOperandType type, const std::string &value)
{
  int	i = 0;

  while ((tab_fct[i].type) != type && (tab_fct[i].type != NOTHING))
    i++;
  return((this->*tab_fct[i].ptr)(value));
}

IOperand *VM::createFloat(const std::string &value)
{
  checkFlow(FLOAT, toNumber<double>(value));
  IOperand      *newOp = new Float(toNumber<float>(value), FLOAT);
  return (newOp);
}

IOperand *VM::createDouble(const std::string &value)
{
  checkFlow(DOUBLE, toNumber<double>(value));
  IOperand      *newOp = new Double(toNumber<double>(value), DOUBLE);
  return (newOp);
}

IOperand *VM::createInt32(const std::string &value)
{
  checkFlow(INT32, toNumber<double>(value));
  IOperand      *newOp = new Int32(toNumber<int>(value), INT32);
  return (newOp);
}

IOperand *VM::createInt16(const std::string &value)
{
  checkFlow(INT16, toNumber<double>(value));
  IOperand      *newOp = new Int16(toNumber<short>(value), INT16);
  return (newOp);
}

IOperand *VM::createInt8(const std::string &value)
{
  checkFlow(INT8, toNumber<double>(value));
  IOperand      *newOp = new Int8(toNumber<short>(value), INT8);
  return (newOp);
}
